

public class Main{

	public static String getPostfix1(String infix) {
		String postfix = "";
		String stack = "";

		for (int i = 0; i < infix.length(); i++) {
			char token = infix.charAt(i);
			if (token == '(' || "+-/^*".indexOf(token) != -1) {
				stack += token;
			} else if (token == ')') {
				int index = stack.lastIndexOf('(');
				postfix += stack.substring(index + 1);
				stack = stack.substring(0, index);
			} else {
				postfix += token;
			}

		}

		return postfix;
	}

	
	public static void main(String[] args) throws java.lang.Exception {
		java.io.BufferedReader r = new java.io.BufferedReader(
				new java.io.InputStreamReader(System.in));
		int number = Integer.parseInt(r.readLine());
		for (int i = 0; i < number; i++) {
			String s = r.readLine();
			System.out.println(getPostfix1(s.trim()));
		}
	}
}
